const { default: api } = require("../../../utils/api");
const message = require("../../../utils/message");

// pages/retail/extract/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        retail_id:null,
        page_index:1,
        has_load:false,
        no_data:false,
        retail_extract_list:[],
        status:0

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        if(options.id){
            this.setData({
                retail_id: options.id
            })


        }



    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

        if(this.retail_id!=null){
            this.getRetailUserExtractList();
        }

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    getRetailUserExtractList:function (  ) {
        var me = this;

        var params = {};
        params.retail_id = this.data.retail_id;

        var page_index  = this.data.page_index;
        if(this.data.has_load){
            page_index++;
        }
        
        params.page_index = page_index;
        params.status = this.data.status;

        message.show_loading();
        api.retail.getRetailUserExtractList( params , function (response) {
            message.hide_loading();
            if( response.status==1 ){
                

                var no_data = false;
                if( response.data.length< 10 ){

                    no_data = true;
                }
                
                var extract_list = me.data.retail_extract_list;

                extract_list = extract_list.concat(response.data);

                me.setData({
                    page_index: page_index,
                    no_data: no_data,
                    retail_extract_list: extract_list,
                    has_load: true
                })
            }else{

                message.show_error( response.message )

            }
        })
        
    },
    selectTab:function ( e ) {
        var status = e.currentTarget.dataset.status;
        this.setData({
            status: status,
            no_data:false,
            page_index:1,
            has_load: false,
            retail_extract_list:[]
        })

        this.getRetailUserExtractList();
    }
})